package com.bootdo.app.controller;

import com.bootdo.app.common.msg.Response;
import com.bootdo.app.service.UserGroupBuyService;
import com.bootdo.app.vo.miniprogram.UserGroupBuyVo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @auther: Along
 * @description: 用户拼团
 * @Date: created in 2020/12/11 15:33
 */
@RestController
@RequestMapping(value = "/app/user_group_buy")
public class UserGroupBuyController {


    @Autowired
    private UserGroupBuyService userGroupBuyService;

    /**
     * 创建拼团
     * @param goodsId 拼团的商品 id
     * @return
     */
    @PostMapping(value = "/make")
    public Response makeGroupBuy(@RequestParam("goodsId")String goodsId){
    	UserGroupBuyVo makeGroupBuy = userGroupBuyService.makeGroupBuy(goodsId);
    	if(makeGroupBuy == null) {
    		return Response.fail("一个月只能创建一次");
    	}
    	return Response.success(makeGroupBuy);
    }

    /**
     * 加入拼团
     */
//    @PostMapping(value = "/join")
//    public Response joinGroupBuy(@RequestParam("groupBuyId")Integer groupBuyId){
//        return Response.success(userGroupBuyService.joinGroupBuy(groupBuyId));
//    }

    /**
     * 取消拼团
     */
    @PostMapping(value = "/cancel")
    public Response cancelGroupBuy(@RequestParam("groupBuyId")Integer groupBuyId){
        userGroupBuyService.cancelGroupBuy(groupBuyId);
        return Response.success();
    }

}
